//
//  Dog2.m
//  2、Person
//
//  Created by student on 16/3/13.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "Dog2.h"

@implementation Dog2

-(instancetype)init{
    
    if (self=[super init]) {
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(hungryDown:) userInfo:nil repeats:YES];
        self.hungry=100;
        self.die=NO;
    }
    return self;
}

-(void)setFirstName:(NSString *)firstName{
    _firstName=firstName;
    NSLog(@"主人你好!我叫%@,请多关照!",firstName);
}

-(NSString *)fullName{
    return [NSString stringWithFormat:@"%@.%@",self.firstName,self.lastName];
}


-(NSString *)lastName{
    if (_lastName==nil) {
        return @"华盛顿";
    }else{
        return _lastName;
    }
}

-(void)hungryDown:(NSTimer *)t{
    
    if (self.hungry>60) {
        self.hungry-=10;
        NSLog(@"%@的饥饿值为%i",self.fullName,self.hungry);
    }else if(self.hungry>0){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"veryHungry" object:self];
        self.hungry-=10;
        NSLog(@"%@的饥饿值为%i,主人我要吃饭呀",self.fullName,self.hungry);
    }else{
        NSLog(@"%@饿死了",self.fullName);
        self.die=YES;
        [t invalidate];
    }
    //    [self.degelate feed:self];
}

@end
